package com.syaccp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.syaccp.model.TOrder;
import com.syaccp.model.TOrderDetail;
import com.syaccp.page.pageUtils;
import com.syaccp.request.TOrderMaterialRequest;
import com.syaccp.service.TOrderDetailService;
import com.syaccp.mapper.TOrderDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author DX
* @description 针对表【t_order_detail】的数据库操作Service实现
* @createDate 2023-07-25 09:12:24
*/
@Service
public class TOrderDetailServiceImpl extends ServiceImpl<TOrderDetailMapper, TOrderDetail> implements TOrderDetailService{

    @Autowired
    TOrderDetailMapper tOrderDetailMapper;

    @Autowired
    TOrderServiceImpl tOrderService;


    @Override
    public int queryInfoByConditionsNumber(TOrderMaterialRequest orderMaterialRequest) {
        return tOrderDetailMapper.queryInfoByConditionsNumber(orderMaterialRequest);
    }


    @Override
    public List<TOrderDetail> queryInfoByConditions(TOrderMaterialRequest orderMaterialRequest, pageUtils page) {
        return tOrderDetailMapper.queryInfoByConditions(orderMaterialRequest, page);
    }

    @Override
    public List<TOrderDetail> queryAuditions() {
        LambdaQueryWrapper<TOrderDetail> queryWrapper = Wrappers.lambdaQuery(TOrderDetail.class);
        queryWrapper.isNotNull(TOrderDetail::getZpshName);
        queryWrapper.groupBy(TOrderDetail ::getZpsh);
        return tOrderDetailMapper.selectList(queryWrapper);
    }

    @Override
    public List<TOrderDetail> queryModelNames() {
        LambdaQueryWrapper<TOrderDetail> queryWrapper = Wrappers.lambdaQuery(TOrderDetail.class);
        queryWrapper.groupBy(TOrderDetail ::getModelId);
        return tOrderDetailMapper.selectList(queryWrapper);
    }

    @Override
    public List<TOrderDetail> queryCompanyNames() {
        LambdaQueryWrapper<TOrderDetail> queryWrapper = Wrappers.lambdaQuery(TOrderDetail.class);
        queryWrapper.groupBy(TOrderDetail ::getCompanyId);
        return tOrderDetailMapper.selectList(queryWrapper);
    }

    @Override
    public Integer delInfoByIds(List<Integer> ids) {
        return tOrderDetailMapper.deleteBatchIds(ids);
    }

    @Override
    public Integer updateSelection(List<Integer> ids) {
        TOrderDetail torderDetail= new TOrderDetail();
        LambdaUpdateWrapper<TOrderDetail> updateWrapper= new LambdaUpdateWrapper<>();
        updateWrapper.in(TOrderDetail ::getId,ids);
        torderDetail.setJingpin(1);
        return tOrderDetailMapper.update(torderDetail,updateWrapper);
    }


}




